/**
 * 字符串 => 整数
 *
 * "123" => ['0', '1', '2', '\0']
 *  - 1) 0*10 + 1 => 1
 *  - 2) 1*10 + 2 => 12
 *  - 3) 12*10 + 3 = > 123
 */

// skip whitespace
int isspace(int x)
{
  if(x==' '||x=='\t'||x=='\n'||x=='\f'||x=='\b'||x=='\r')
    return 1;
  else
    return 0;
}

int atoi(const char *nptr)
{
  int c;
  int total;

  // 不断往后的遍历 str[i] 每一个字符
  while (isdigit(c))
  {
    total = 10 * total + (c - '0'); // sum = 10 * sum + 取余位
    c = (int)(unsigned char)*nptr++; // next char
  }

  return total;
}